<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="assets/ico/favicon.ico">

    <title>Set admin password</title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <link rel="stylesheet" type="text/css" href="css/bootstrap-select.min.css">
    <link type="text/css" href="css/style.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
      function setpass() {
        $.ajax({
          type: "GET", 
          url: "/cgi-bin/setpass?password="+$('#password').val(),
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          success: function(json) {
              if (json.result == "error") {
                $('#alertMsg').innerHTML="<div class='alert alert-danger'>" + json.message + "</div>"
              }
          },
          error: function(error) {
            //alert("调用出错" + error.responseText);
          }
        });
        document.getElementById('alertMsg').innerHTML="<div class='alert alert-info'>正在重设管理WIFI密码,请修改连接密码后重新连接...</div>"
        return false;
      }
    </script>
  </head>
  <body>
    <div class="navbar navbar-inverse navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container"><a href="/" class="brand">WRTNode Control Panel</a>

        </div>
      </div>
    </div>
    <div class="container">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <div class="panel panel-default">
            <div class="panel-body" id="status">
              正在查看当前状态,请稍后...
            </div>
          </div>
          <ul class="nav nav-sidebar">
            <li class="inactive"><a href="/webui-xhi/setwifi.html">设置WIFI密码</a></li>
            <li class="active"><a href="/webui-xhi/setadm.html">重设管理密码</a></li>
          </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div id="alertMsg"></div>
            <form action="#" method="post" onsubmit="return setpass();" class="well">
            <fieldset>
              <legend>设置WIFI密码</legend>
              <div class="form-group">
                <label for="ssid">本设备接入点名</label>
                <div id="ssidname">正在获取SSID...</div>
              </div>
              <div class="form-group">
                <label for="password">无线密码</label>
                <input id="password" type="password" name="password" class="form-control"/>
              </div>

              <div style="margin: 20px 0;">
                <button type="submit" class="btn btn-primary">保存</button>
              </div>
            </fieldset>
          </form>
        </div>
      </div>
      <hr>
    </div>
  </body>
  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <script type="text/javascript" src="js/docs.min.js"></script>
  <script type="text/javascript" src="js/bootstrap-select.min.js"></script>
  <script type="text/javascript">
      $(window).on('load', function () {
        $.ajax({
          type: "GET", 
          url: "/cgi-bin/getssid",
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          success: function(json) {
            if (json.result == "success") {
              $("#ssidname").text(json.ssid)
            }
            else {
              $("#ssidname").text(json.message)
            }
          },
          error: function(error) {
            //alert("调用出错" + error.responseText);
          }
        });
        $.ajax({
          type: "GET", 
          url: "/cgi-bin/checkwifi",
          dataType: "json",
          contentType: "application/json; charset=utf-8",
          success: function(json) {
              if (json.result=="success") {
                $("#status").text("已连接路由器，当前IP:" + json.ip)
              }
              else {
                $('#status').text("未连接路由器")
              }
          },
          error: function(error) {
            alert("调用出错" + error.responseText);
          }
        });

      });
  </script>
</html>
